package com.wlyy.bcwlw.common.export2excel.impl;

import java.math.BigDecimal;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.wlyy.bcwlw.common.export2excel.inter.ICellValueSetter;
import com.wlyy.bcwlw.common.utils.ExcelUtil;

public class NumberCellValueSetter implements ICellValueSetter {

	
	public static final NumberCellValueSetter INSTANCE = new NumberCellValueSetter();
	
	@Override
	public void setCellValue(HSSFWorkbook wb, HSSFSheet sheet, HSSFCell cell,
			Object value) {
		// TODO Auto-generated method stub
		cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
		
		if(value !=null){
			if(value instanceof BigDecimal){
				cell.setCellValue(((BigDecimal)value).doubleValue());
			}else{
				try{
					cell.setCellValue((new BigDecimal(String.valueOf(value)).doubleValue()));
				}catch(Exception ex){
					ExcelUtil.setText(cell, String.valueOf(value));
				}
			}
		}
		
	}

}
